package com.anlu.kafka.selfserial;

import com.anlu.kafka.config.BusiConst;
import com.anlu.kafka.config.KafkaConst;
import com.anlu.kafka.vo.DemoUser;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

public class SelfSerialProducer {
    private static KafkaProducer<String,DemoUser> producer = null;

    public static void main(String[] args) {
          /*消息生产者*/
        producer = new KafkaProducer<String, DemoUser>(KafkaConst.producerConfig(
                StringSerializer.class,SelfSerializer.class
        ));

        try{
            //待发送消息的消息实例
            ProducerRecord<String,DemoUser> record;
            try{
                record = new ProducerRecord<String, DemoUser>(BusiConst.SELF_SERIAL_TOPIC,"user01",new DemoUser(1,"mark"));
                producer.send(record);
                System.out.println("sent ");

            }catch (Exception e){
                e.printStackTrace();
            }

        }finally {
            producer.close();
        }
    }
}
